package cn.tedu.spring.begin;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserTest {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        /**
         方式1：通过spring创建 java bean 对象
         1.加载spring配置文件(bean.xml)
         2.获取spring创建好的对象
         3.打印测试(调add方法)
         */
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        User user = (User) context.getBean("user");
        System.out.println("user = " + user);
        user.add();

        /** 方式2：new方式创建java对象 */
        User user2 = new User();
        System.out.println("user2 = " + user2);
        user2.add();

        /** 方式3：反射方式创建java对象
         1.获取class对象
         2.调用方法进行创建
         */
        Class zz = Class.forName("cn.tedu.spring.begin.User");
        User user3 = (User) zz.newInstance();
        System.out.println("user3 = " + user3);
        user3.add();
    }
}
